package com.example.javaow.controller;/*
 * @Auther:Sadie
 * @Date:2025/8/12
 * @Description:
 * @VERSON:1.8
 */

import com.example.javaow.domain.base.ResponseResult;
import com.example.javaow.domain.dto.DeviceGroupDto;
import com.example.javaow.service.DeviceGroupService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/devicegroup")
@RequiredArgsConstructor
@Slf4j
public class DeviceGroupController {
    @Autowired
    private DeviceGroupService devicegroupservice;
    //添加分组
    @PostMapping("/add")
    public ResponseResult add(@RequestBody DeviceGroupDto deviceGroupDto) {
        log.info("添加分组：{}", deviceGroupDto);
        return devicegroupservice.add(deviceGroupDto);
    }

    // 修改分组
    @PutMapping("/update")
    public ResponseResult update(@RequestBody DeviceGroupDto deviceGroupDto) {
        log.info("修改分组：{}", deviceGroupDto);
        return devicegroupservice.update(deviceGroupDto);
    }

    // 删除分组（支持批量）
    @DeleteMapping("/delete")
    public ResponseResult delete(@Param("ids") Long[] ids) {
        log.info("删除分组ID列表：{}",  ids);
        return devicegroupservice.delete(ids);
    }

    // 根据ID查询详情
    @GetMapping("/{id}")
    public ResponseResult getById(@PathVariable Long id) {
        log.info("查询分组详情，ID：{}", id);
        return devicegroupservice.getById(id);
    }

    // 查询全部
    @GetMapping("/list")
    public ResponseResult getAll() {
        log.info("查询所有分组");
        return devicegroupservice.getAll();
    }

    // 条件查询
    @GetMapping("/search")
    public ResponseResult getByCondition(
            @RequestParam(required = false) Long parentId,
            @RequestParam(required = false) String name) {
        log.info("条件查询分组 - 父ID：{}，名称包含：{}", parentId, name);
        return devicegroupservice.getByCondition(parentId, name);
    }

}
